import { pAjax } from "../../index/javascripts/gather";
//获取元素
const form = document.querySelector('form');
const userName = document.querySelector('.username');
const passWord = document.querySelector('.password');
const rpass = document.querySelector('.rpassword');
const nickName = document.querySelector('.nickname');
const errorBox = document.querySelector('.error')

form.addEventListener('submit',async e =>{
    e.preventDefault();
    //用户输入内容 
    let yong = {
        username : userName.value,
        password : passWord.value,
        rpassword : rpass.value,
        nickname : nickName.value
        
    }
    let res = await pAjax({
        url: 'http://localhost:8888/users/register',
        method:'post',
        data:yong,
        dataType:'json',
    })
    console.log(res)
    if (res.code !== 1) return errorBox.style.display = 'block'
    alert('恭喜您注册成功')
    window.location.href = './login.html'
})


